package com.gt.data;

import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Console;
import cn.hutool.setting.Setting;

import java.util.Date;

public class GlobalData {

    //项目配置
    public static Setting setting = new Setting("config.setting");

    //会战开始日期 会战持续13天，休8天
    public static String HUIZHAN_BEGIN_TIME = "2021-07-30 12:00:00";



    public static Date[] fetchHuizhanBeginAndEndTime(){
        Date huizhan_begin_time = DateUtil.parseDateTime(HUIZHAN_BEGIN_TIME);
        long day = DateUtil.between(huizhan_begin_time, new Date(), DateUnit.DAY);
        Console.log("从2021-07-30 12:00:00至今有{}天",day);
        long round = day / 21;
        day = day % 21;
        //会战开始时间
        Date curHuizhanBeginTime = DateUtil.offsetDay(huizhan_begin_time,(int)(round * 21));
        Date curHuizhanEndTime = DateUtil.offsetDay(curHuizhanBeginTime,13);
        String str1 = DateUtil.formatDateTime(curHuizhanBeginTime);
        String str2 = DateUtil.formatDateTime(curHuizhanEndTime);
        Console.log("当前会战开始时间:{},结束时间:{}",str1,str2);
        return new Date[]{curHuizhanBeginTime,curHuizhanEndTime};
    }

    public static String getValue(String key){
        return setting.get(key);
    }


}
